<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('评论列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>文章标题：</label>
                                <input type="text" name="contentTitle"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"  >
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var kind = [[${kind}]]
        var prefix = ctx + "news/comment";

        $(function() {
            var options = {
                url: prefix + "/list?kind=" + kind,
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "评论",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'contentTitle',
                    title: '文章标题',
                    width: 200,
                    formatter: function(val, row) {
                        return '<a onClick="onView(\''+row.contentId+'\')">'+val+'</a>'
                    }
                },
                {
                    field: 'userName',
                    title: '回复人',
                    width: '150px'
                },
                {
                    field: 'content',
                    title: '回复内容',
                    width: 300
                },
                {
                    field: 'status',
                    title: '状态',
                    width: '150px',
                    formatter: function(val) {
                        if(val == 0) return '<span class="label label-default">待审核</span>'
                        else if(val == 1) return '<span class="label label-info">审核通过</span>'
                        else if(val == 2) return '<span class="label label-warning">审核不通过</span>'
                    }
                },
                {
                    field: 'ip',
                    title: 'ip',
                    width: '150px'
                },
                {
                    field: 'address',
                    title: '地址',
                    width: 180
                },
                {
                    field: 'createTime',
                    title: '回复时间',
                    width: '150px'
                },

                {
                    title: '操作',
                    align: 'center',
                    width: 250,
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(!row.status || row.status == '0') {
                            actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="doUpdate(\'' + row.id + '\', 1)"><i class="fa fa-check"></i>审核通过</a> ');
                            actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="doUpdate(\'' + row.id + '\', 2)"><i class="fa fa-close"></i>审核不通过</a> ');
                        } else if(row.status == '1') {
                            actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="doUpdate(\'' + row.id + '\', 2)"><i class="fa fa-close"></i>审核不通过</a> ');
                        } else if(row.status == '2') {
                            actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="doUpdate(\'' + row.id + '\', 1)"><i class="fa fa-check"></i>审核通过</a> ');
                        }

                        actions.push('<a class="btn btn-danger btn-xs  " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function doUpdate(id, status) {
            var url = prefix + "/edit";
            var data = {
                id: id,
                status: status
            };
            $.operate.post(url, data, function(data) {
                $.table.refresh();
            })
        }

        function onView(id) {
            $.modal.openTab("预览", ctx + 'news/content/newsPreview/' + id );
        }
    </script>
</body>
</html>